package utils

import "golang.org/x/crypto/bcrypt"

// encode password
func HashPwd(pwd string) (string, error) {
	hashedPwd, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	return string(hashedPwd), nil
}

func CheckPasswordHash(password, hash string) bool {
	// 比较明文密码和哈希密码
	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
	return err == nil
}
